package com.fx.controller;

import com.fx.common.AbstractWindowController;
import com.fx.view.ExceptionPageView;
import de.felixroske.jfxsupport.FXMLController;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.stage.WindowEvent;
import org.springframework.beans.factory.annotation.Autowired;

import java.net.URL;
import java.util.ResourceBundle;

@FXMLController
public class ExceptionPageController extends AbstractWindowController implements Initializable {

    @FXML
    private Label errorMessage;

    @Autowired
    private ExceptionPageView exceptionPageView;

    private String message;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        if(errorMessage != null){
            errorMessage.setText(message);
        }
    }

    public void setErrorText(String message){
        this.message = message;
    }

    @FXML
    private void close(Event e){
        closeWindow();
    }

    @Override
    protected void makeRoot() {
        setRoot(exceptionPageView.getView());
    }

    @Override
    public void onCloseRequest(WindowEvent e) {
        closeWindow();
    }
}
